function policy(){ // metodo de construção const policyContent = $('.policy_text'); const policyMenu = $('.policy_menu'); // escondendo todos os elementos policyContent.hide(); policyContent.first().show(); // inserindo classe no primeiro elemento do menu policyMenu.find('li').first().find('a').addClass('active'); } policy.prototype = { agreeButtonClick : function (userId, textId, cartId, orderId, useImageFan, urlRedir) { $(window).scrollTop(0); if ($('#agree_check'+textId).is(":checked")) { if (this.checkIfLastTextInformation(textId, userId, cartId, orderId, urlRedir)) { if (useImageFan && typeof useImageFan != 'undefined') { window.location.href = '/user-media'; } window.location.href = urlRedir; } this.disableCheckBox(textId); //mostra o proximo texto que não foi marcado $('.policy_text').hide(); $('#id_' + textId).next().show(); var next = $('#id_' + textId).next().attr('id'); $('.policy_menu li').find('a').removeClass('active'); $('.policy_menu li').find('a[href="#'+next+'"]').addClass('active'); } }, checkBoxClick : function (userId, textId, cartId, orderId) { if ($('#agree_check'+textId).is(":checked")) { this.insertUserCheckLog(userId,textId, cartId, orderId); this.ableAgreeButton(textId); this.disableCheckBox(textId); } else { this.disableAgreeButton(textId); } }, disableCheckBox : function (textId) { $('#agree_check'+textId).prop('disabled', true); }, ableAgreeButton : function (id) { $('#agree_button_'+id).removeAttr('disabled'); }, disableAgreeButton : function (id) { $('#agree_button_'+id).attr('disabled', 'disabled'); }, checkIfLastTextInformation : function (textId, userId, cartId, orderId, urlRedir) { let thisObject = this; $.ajax({ url: '/policy/check-if-last-text-information', method: 'post', data: {textId: textId, userId: userId, cartId: cartId, orderId: orderId}, dataType: 'json', error: function(json) { alert('Ocorreu um problema tente novamente'); }, success: function(json) { if(json.status){ if (json.lastTextInformation) { if (json.useImage == true) { window.location.href = '/user-media'; return; } else { window.location.href = urlRedir; } } else { thisObject.showNextTextInformation(); } } else { alert(json.message); } }, }); }, showNextTextInformation : function () { console.log(this); }, insertUserCheckLog : function (userId, textId, cartId, orderId) { let thisObject = this; $.ajax({ url: '/policy/insert-user-check-log', method: 'post', data: { userId: userId, textId: textId, cartId: cartId, orderId: orderId }, dataType: 'json', xhrFields: { withCredentials: true }, error: function(json) { }, success: function(json) { }, }); } } var policy = new policy();